/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import database.Database;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Scott
 */
public class RosterDialog extends JDialog {

    Database db;
    private JFrame mainFrame;
    private JDialog chooserFrame;
    private JPanel chooserPanel;
    private JButton administrator;
    private JButton instructor;
    private JButton student;
    RosterListPanes rlp;

    public RosterDialog(Database db, JFrame main, RosterListPanes rlp) {
        this.db = db;
        this.mainFrame = main;

        chooserFrame = new JDialog();
        chooserPanel = new JPanel();
        this.rlp = rlp;

        showChoices();

    }

    private void showChoices() {

        constructChoices();

        chooserFrame.setBounds(300, 200, 100, 100);
        chooserFrame.getContentPane().add(chooserPanel);
        chooserFrame.pack();
        chooserFrame.setVisible(true);
        chooserFrame.setResizable(false);

    }

    private void constructChoices() {
        administrator = new JButton("Administrators");
        instructor = new JButton("Intructors");
        student = new JButton("Students");

        administrator.addActionListener(new adminSelectionListener());
        instructor.addActionListener(new instructorSelectionListener());

        chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.Y_AXIS));
        chooserPanel.add(administrator);
        chooserPanel.add(instructor);
        chooserPanel.add(student);

    }

    class adminSelectionListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            //Administrators selected show administrators
            mainFrame.getContentPane().add(rlp.getAdminPanel(), BorderLayout.WEST);
            mainFrame.pack();
            mainFrame.setSize(400, 600);
            mainFrame.setLocationRelativeTo(null);
            mainFrame.setResizable(false);
            chooserFrame.dispose();
        }
    }

    class instructorSelectionListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            //nstructors selected show instructors
            mainFrame.getContentPane().add(rlp.getInstPanel(), BorderLayout.WEST);
            mainFrame.pack();
            mainFrame.setSize(400, 600);
            mainFrame.setLocationRelativeTo(null);
            mainFrame.setResizable(false);
            chooserFrame.dispose();
        }
    }

    class studentSelectionListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            //nstructors selected show instructors
            mainFrame.getContentPane().add(rlp.getStudentPanel(), BorderLayout.WEST);
            mainFrame.pack();
            mainFrame.setSize(400, 600);
            mainFrame.setLocationRelativeTo(null);
            mainFrame.setResizable(false);
            chooserFrame.dispose();
        }
    }
}//end class RosterDialog
